/**
 * @a https://leetcode.cn/problems/merge-intervals/
 */

#include "../common.h"

class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        sort(intervals.begin(), intervals.end(), [](vector<int>& v1, vector<int>& v2){
            return v1[0] < v2[0];
        });
        vector<vector<int>> ret;
        int cur = 0, sz = intervals.size();
        for(vector<int> vec : intervals){
            if(ret.empty() || ret.back()[1] < vec[0]){
                ret.push_back(vec);
            }
            ret.back()[1] = max(ret.back()[1],vec[1]);
        }
        return ret;
    }
};